home *** CD-ROM | disk | FTP | other *** search
- Path: ohstpy.mps.ohio-state.edu!vancleef
- From: vancleef@ohstpy.mps.ohio-state.edu
- Newsgroups: comp.lang.c
- Subject: Re: Why isn't return address in the stack protected?
- Message-ID: <1996Jan24.032914.8805@ohstpy>
- Date: 24 Jan 96 03:29:14 -0500
- References: <DLo4xF.MH@un.seqeb.gov.au>
- Organization: The Ohio State University, Department of Physics
-
- In article <DLo4xF.MH@un.seqeb.gov.au>, al012@svtstu.seqeb.gov.au (Anthony Lee) writes:
- > void log_event(void)
- > {
- > char message[256];
- > int i;
- >
- > sprintf(message,
- > " Event, node: %d, seq:%08.8x, type:%02.2d,
- > length:%03.3d, data: ",
- > nodeid, me.seqno, me.type, me.length);
- >
- > for ( i = 0; i < me.length; i++)
- > sprintf(&message[strlen(message)],"%02.2x
- > ",me.data.array[i] & 0xff);
- > printf("%s\n", message);
- >
- > }
- >
- > In the above code if the me.length is such that the resultant
- > string is longer than the size of message (> 256 bytes). Then
- > my C program would happily sprintf into message. The problem is
- > that it starts writing all over the stack causing the program
- > to fall over. My question is why can't the run time environment
- > protect the stack from such access and flag an error?
- > --
-
- Because that's the way C works. It doesn't do anything more
- than you specifically ask for. If it did, you wouldn't have
- control over your application, the compiler would. Programming
- in C is a double edged sword, if you don't like it you
- should stick to Fortran.
-
- -Garrett
-
-
-
- > Anthony Lee These are my opinions and not SEQEB.
- > SEQEB
- > 150 Charlotte Street ..-- __o
- > Brisbane ....-- _ \<,_
- > Qld 4000 ____ (_)/ (_)
- >
- > Australia
- > voice:+61 7 3407 4541 Death to the Daleks!!!!
- > fax: +61 7 3407 4607
- > email: AL012@svtstu.seqeb.gov.au
- >
-